package com.tao.context;


public class UserContext {

    private static final ThreadLocal<Integer> idThreadLocal = new ThreadLocal<>();
    private static final ThreadLocal<String> nameThreadLocal = new ThreadLocal<>();
    private static final ThreadLocal<Integer> roleIdThreadLocal = new ThreadLocal<>();

    public static Integer getThreadUserId(){
        return idThreadLocal.get();
    }

    public static void setThreadUserId(Integer id){
        idThreadLocal.set(id);
    }


    public static Integer getThreadUserRoleId(){
        return roleIdThreadLocal.get();
    }

    public static void setThreadUserRoleId(Integer id){
        roleIdThreadLocal.set(id);
    }

    public static String getThreadUserName(){
        return nameThreadLocal.get();
    }

    public static void setThreadUserName(String name){
        nameThreadLocal.set(name);
    }

    public static void clear(){
        idThreadLocal.remove();
        nameThreadLocal.remove();
        roleIdThreadLocal.remove();
    }
}
